package only.my.railgunys.utils;

import only.my.railgunys.artifact.IncreaseFunction;
import only.my.railgunys.bean.Character;
import only.my.railgunys.bean.Enemy;
import only.my.railgunys.bean.Weapon;

import java.util.List;

public class FightUtils {
    //
    public static int calcTotalDmg(Character character){
        Double 技能倍率 = character.getSkillDmg();
        Double 攻击白字 = character.getAtk();
        Double 攻击绿字 = character.getAtk_ex();
        double 暴击率 = character.getCritRate()/100;
        暴击率 = 暴击率 >1?1:暴击率;
        double 暴击伤害 = character.getCritDmg()/100;

        double 伤害加成 = character.getIncrease()/100;

        Double reaction = character.getReaction();
        double 元素反应倍率 = 1;
        if (reaction > 1.0) {
            double 精通提升 = 2.78*character.getMastery()/(character.getMastery()+1400);
            元素反应倍率 = reaction *(1+ 精通提升 + character.getReactionIncrease());
        }


        int clv = character.getLevel() + 100;
        Enemy enemy = character.getEnemy();
        double v = (1 - enemy.getDefenceReduce()) * (enemy.getLevel() + 100);
        Double 敌人防御承伤 = clv /(clv+ v); //190/(190+(1-e))
        Double 抗性承伤=1D;
        if(enemy.getResistance() > character.getResistance()){
            抗性承伤 = 1- (enemy.getResistance()-character.getResistance());
        }else if(enemy.getResistance() < character.getResistance()){
            抗性承伤 = 1- (enemy.getResistance()-character.getResistance())/2;
        }
        double 总伤害 = 技能倍率*(攻击白字+攻击绿字)*(1+伤害加成)*(1+暴击率*暴击伤害)*元素反应倍率*敌人防御承伤*抗性承伤;
        int totalDmg = (int) 总伤害;
        if(totalDmg == 7835742){
            System.out.println(totalDmg+"");
        }
        character.setTotalDmg(totalDmg);
        return totalDmg;
    }

    public static List<Character> calcSuitIncrease(Character character, Weapon weapon, IncreaseFunction piece2, IncreaseFunction piece4){

        weapon.mainStatEnhance(character);

        List<Character> temp = ArtifactSetUtils.mainStatRollEnhance(character);
        List<Character> characters = ArtifactSetUtils.possibleStatRollEnhance4(temp,25);

        characters.stream()
                .map(piece2::setEffectPiece)
                .map(piece4::setEffectPiece)
                .map(weapon::subStatEnhance)
                .map(weapon::specialAbility)
                .forEach(FightUtils::calcTotalDmg);
        return characters;
    }
    public static List<Character> calcSuitIncrease(Character character, Weapon weapon, IncreaseFunction piece2, IncreaseFunction piece4, IncreaseFunction specialPiece){

        weapon.mainStatEnhance(character);

        List<Character> temp = ArtifactSetUtils.mainStatRollEnhance(character);
        List<Character> characters = ArtifactSetUtils.possibleStatRollEnhance3(temp,25);

        characters.stream()
                .map(piece2::setEffectPiece)
                .map(weapon::subStatEnhance)
                .map(piece4::setEffectPiece)
                .map(weapon::specialAbility)
                .map(specialPiece::setEffectPiece)
                .forEach(FightUtils::calcTotalDmg);
        return characters;
    }

    /**
     *
     * @param status 1 挂冰，2 冻结 ，3 挂水 ，4 挂火
     * @return Enemy
     */
    public static Enemy initNormal90(int status) {
        Enemy enemy = new Enemy();
        enemy.setElementstate(status);// 挂冰
        enemy.setLevel(90);
        enemy.setDefenceReduce(0D);
        enemy.setResistance(0.1);
        return enemy;
    }

}
